三种动画方式 帧动画 属性动画 补间动画

1.帧动画 

AnimationDrawable animationDrawable = new AnimationDrawable();
//添加动画
animationDrawable.addFrame(getDrawable(R.drawable.q),100);
animationDrawable.addFrame(getDrawable(R.drawable.w),100);
animationDrawable.addFrame(getDrawable(R.drawable.e),100);
animationDrawable.addFrame(getDrawable(R.drawable.r),100);
animationDrawable.addFrame(getDrawable(R.drawable.t),100);
animationDrawable.addFrame(getDrawable(R.drawable.y),100);
animationDrawable.addFrame(getDrawable(R.drawable.u),100);
animationDrawable.addFrame(getDrawable(R.drawable.i),100);
animationDrawable.addFrame(getDrawable(R.drawable.o),100);
animationDrawable.addFrame(getDrawable(R.drawable.p),100);

animationDrawable.setOneShot(false);  //false 一直循环  
img.setImageDrawable(animationDrawable); //动画 赋给 img
animationDrawable.start(); //开始动画

2.补间动画

        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 3, 2, 0);
        ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 0, 200);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 1, 2);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 1, 2);

        AnimatorSet animatorSet = new AnimatorSet();    //集合 动画
        animatorSet.setTarget(alpha);                   //往集合 添加动画
        animatorSet.setTarget(rotation);
        animatorSet.setTarget(scaleX);
        animatorSet.setTarget(scaleY);
        animatorSet.setDuration(4000);   //4秒播放完
        animatorSet.playSequentially(rotation,scaleX,scaleY,alpha); //按顺序播放动画
        animatorSet.start(); //开始动画

3.属性动画 ofFloat 三个参数  图片 动画类型  数值

        ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 3, 2, 0);   //逐渐消失 
        ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 0, 200); //旋转
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 1, 2);  //X横向 放大两倍
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 1, 2);//Y横向 放大两倍
        alpha.setDuration(3000);    
        alpha.setInterpolator(new LinearInterpolator());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值